package android.pot.com.smartcar.base;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.pot.com.smartcar.R;
import android.pot.com.smartcar.config.MyConfig;
import android.pot.com.smartcar.util.Utils;
import android.support.v4.app.Fragment;
import android.view.View;

import java.io.File;

import static android.app.Activity.RESULT_FIRST_USER;

/**
 * Created by zhaoshilu on 2017/7/18.
 */

public abstract class BaseFragment extends Fragment implements View.OnClickListener{
    /**
     * 初始化控件
     **/
    protected abstract void initView(View view);

    /**
     * 添加监听事件
     **/
    protected abstract void addListener();

    /**
     * 加载数据
     */
    protected abstract void initData();

    public  final int REQUEST_CODE = 1000;
    @Override
    public void onClick(View v) {
        if (Utils.isFastDoubleClick(500)) {
            return;
        }

    }

    protected void checkNetwork() {
        if (!Utils.isNetworkConnected(getActivity())) {
            Utils.showToast(getActivity(), R.string.hint_please_check_network);
            return;
        }
    }

    @Override
    public void onResume() {
        super.onResume();


        File tempDir = new File(MyConfig.TEMP_IMG_PATH);
        if (!tempDir.exists()) {
            tempDir.mkdirs();
        }
    }

    protected void startAct(Context context, Class<?> cls) {
        Intent intent = new Intent();
        intent.setClass(context, cls);
        context.startActivity(intent);

    }
    protected void startActForResult(Context context, Class<?> cls){
        Intent intent = new Intent();
        intent.setClass(context, cls);
        ((Activity)context).startActivityForResult(intent,RESULT_FIRST_USER);
    }
    protected void startActForResult(Context context, Class<?> cls,Bundle bundle){
        Intent intent = new Intent();
        intent.setClass(context, cls);
        intent.putExtras(bundle);
        ((Activity)context).startActivityForResult(intent,RESULT_FIRST_USER);
    }
    protected void startAct(Context context, Class<?> cls, Bundle bundle) {
        Intent intent = new Intent();
        intent.setClass(context, cls);
        intent.putExtras(bundle);
        context.startActivity(intent);
    }
}
